<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>件细节-ref用法</title>
</head>
<body>
    <div id="app">
        <div ref="hello" @click="handleClick()">{{content}}</div>
        <counter ref="one" @change="handleChange"></counter>
        <counter ref="two" @change="handleChange"></counter>
        <div >
            {{total}}
        </div>
    </div>
</body>
<script src="vue.js"></script>
<script>
    Vue.component('counter', {
        data: function() {
            return {
                number: 0
            }
        },
        template: '<div @click="handleClick">{{number}}</div>',
        methods: {
            handleClick: function() {
                this.number++;
                this.$emit('change', this.number)
            }
        }
    })
    var app = new Vue({
        el: '#app',
        data: {
            content: 'hello world!',
            total: 0
        },
        methods: {
            handleClick: function() {
                console.log(this.$refs, event)
                console.log(this.$refs.hello === event.target)
                this.$refs.hello.style.color = "red"
            },
            handleChange: function(aa) {
                var one = this.$refs.one.number;
                var two = this.$refs.two.number;
                this.total = one + two;
                 console.log(this.$refs)
            }
        }
    })
</script>
</html>